/**
 * Created by Dalyn on 2017/5/8.
 */
import React from "react";
import {hashHistory} from 'react-router';
import Relay from "react-relay";
import { Table,message,Input } from 'antd';
import ReactKey from "../../../../util/ReactKey";
import GetChildsGoodsMutation from '../../mutation/fabricRawMutation/GetChildsGoodsMutation';
import SaveProductDespMutation from '../../mutation/fabricRawMutation/SaveProductDespMutation';
import "../../css/fabricRaw.css";
import "../../css/productionManagement_common.css";
/*导出组件*/
export default class FabricRaw extends React.Component{

    constructor(props) {
        super(props);
        this.state = {
            editable: true,
            value:'',
            dataSource: [],
            /*允许发送保存请求*/
            saveAllow:true,
        };
        this.orderType={
            1:"成衣",
            2:"辅料",
            3:"面料",
            4:"印染",
            5:"纱线",
        };
        this.orderGoodss =[];
    }

    componentWillMount(){
        this.getChildsGoods()
    }
    getChildsGoods(){
        Relay.Store.commitUpdate(
            new GetChildsGoodsMutation({
                orderId: this.props.orderId,
            }),
            {
                onFailure: () => {
                    message.error('网络请求失败');
                },
                onSuccess: (response) => {
                    let errorCode = response.getChildsGoods.getChildsGoods.errorCode;
                    if (errorCode == 0) {
                        let orderGoodss = response.getChildsGoods.getChildsGoods.orderGoodss;
                        this.orderGoodss = orderGoodss;
                        this.setState({
                            dataSource: orderGoodss,
                        })
                    } else {
                        if (errorCode == 500){
                            message.error('服务器错误,请联系系统管理员');
                        }
                    }
                }

            }
        );
    }

    render(){
        const { dataSource } = this.state;
        const columns = [{
            title: '序号',
            dataIndex: 'index',
            key: 'index',
            render: ((text, record, index) =>{
                return index+1
            })
        }, {
            title: '采购订单',
            dataIndex: 'orderId',
            key: 'orderId',
            width: 200,
            render: ((text, record, index) =>{
                return <span title={record.orderId}>{record.orderId}</span>
            }),
        },{
            title: '供应商',
            dataIndex: 'partBName',
            key: 'partBName',
            width: 200,
            render: ((text, record, index) =>{
                return <span title={record.partBName}>{record.partBName}</span>
            }),
        }, {
            title: '品名',
            dataIndex: 'productName',
            key: 'productName',
            width: 200,
            render: ((text, record, index) =>{
                return <span title={record.productName}>{record.productName}</span>
            }),
        }, {
            title: '类别',
            dataIndex: 'orderType',
            key: 'orderType',
            render: ((text, record, index) =>{
                return <span>{this.orderType[record.orderType]}</span>
            }),
        }, {
            title: '规格',
            dataIndex: 'specification',
            key: 'specification',
            render: ((text, record, index) =>{
                return <span>{record.specification}</span>
            }),
        }, {
            title: '颜色',
            dataIndex: 'colour',
            key: 'colour',
            render: ((text, record, index) =>{
                return <span>{record.colour}</span>
            }),
        }, {
            title: '单位',
            dataIndex: 'prickle',
            key: 'prickle',
            render: ((text, record, index) =>{
                return <span>{record.prickle}</span>
            }),
        }, {
            title: '订单数量',
            dataIndex: 'quantity',
            key: 'quantity',
            render: ((text, record, index) =>{
                return <span>{record.quantity}</span>
            }),
        }, {
            title: '到货数量',
            dataIndex: 'acceptQuantity',
            key: 'acceptQuantity',
            render: ((text, record, index) =>{
                return <span>{record.acceptQuantity}</span>
            }),
        }, {
            title: '差异数量',
            dataIndex: 'difference',
            key: 'difference',
            render: ((text, record, index) =>{
                return <span>{record.quantity-record.acceptQuantity}</span>
            }),
        }, {
            title: '备注',
            dataIndex: 'productionDesp',
            key: 'productionDesp',
            width: 200,
            render: ((text, record, index) =>{
                return <span title={record.productionDesp}>{record.productionDesp}</span>
            }),
        }
        ];
        return (
            <div className="poduction_manage_tab_box">
                <Table
                    columns={columns}
                    dataSource={this.state.dataSource}
                    bordered
                    rowKey={record => record.gid+record.orderId}
                    style={{width:'100%'}}
                    className="order_table"
                    pagination={false}
                />
            </div>
        )
    }
}
